package com.clstu.homework;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Homework01 {
    public static void main(String[] args) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
//        Class<?> cls = Class.forName("com.clstu.homework.PrivateTest");
        Class<PrivateTest> cls = PrivateTest.class;//也可以直接类名.class得到对应的class对象
        Object o = cls.newInstance();
        Field name = cls.getDeclaredField("name");
        name.setAccessible(true);
        name.set(o,"along");
        Method getName = cls.getDeclaredMethod("getName");
        Object name1 = getName.invoke(o);
        System.out.println(name1);
    }

}
class PrivateTest{
    private String name = "helloKitty";
    public String getName(){
        return name;
    }
}